﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

using UnityEditor;
[InitializeOnLoad]
public class SceneRightClickDetector
{
    static SceneRightClickDetector()
    {
        //监听场景GUI
        //SceneView.duringSceneGui += OnSceneGUI;
    }

    static void OnSceneGUI(SceneView sceneView)
    {
        Event e = Event.current;
        //按下右键
        if (e.type == EventType.MouseDown && e.button == 1)
        {
            //选中了单个物体
            if (Selection.gameObjects != null
                && Selection.gameObjects.Length == 1)
            {
                //在鼠标位置显示右键菜单
                EditorUtility.DisplayPopupMenu(new Rect(e.mousePosition, Vector2.zero), "RightClickMenu/", null);
            }
        }
    }

    [MenuItem("RightClickMenu/Test1")]
    public static void ContextMenuTest1()
    {
        Debug.Log("Test1");
    }

    [MenuItem("RightClickMenu/Test2")]
    public static void ContextMenuTest2()
    {
        Debug.Log("Test2");
    }

    [MenuItem("RightClickMenu/Test3")]
    public static void ContextMenuTest3()
    {
        Debug.Log("Test3");
    }
}
